home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech's Sprocket™ / Sprocket-10.14.95 / SprocketStarter / SprocketStarter.cp < prev    next >
Encoding:
Text File  |  1995-09-20  |  7.8 KB  |  367 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        SprocketSample.cp
  3.  
  4.     Contains:    Boilerplate application-specific code.
  5.                 
  6.     Written by: Dave Falkenburg
  7.  
  8.     Copyright:    © 1993-94 by Dave Falkenburg, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.      
  12.          <7>     12/6/94    DRF        Gave this file a better name. Also stop defining kCreditsBox
  13.                                     here.
  14.          <6>     11/8/94    DRF        (LDR) Modified to pass all non-standard menu selections through
  15.                                     to window obj.
  16.          <5>     11/8/94    DRF        DoEditMenu is gone; call DoMenuSelection instead.
  17.          <4>     9/28/94    DRF        Changes for Dave Mark: More comments & rearranged code.
  18.          <3>     9/27/94    DRF        Changes for Dave Mark: AppLib.h is now Sprocket.h &
  19.                                      clipboard conversion routines are fixed.
  20.          <2>      9/9/94    DRF        Reorganized headers and removed redundant #includes and
  21.                                     conditionalized AOCE support.
  22.  */
  23. #include "SprocketStarter.h"
  24. TLinkedList        *gListPtr;
  25.  
  26. #include "Sprocket.h"
  27. #include "Window.h"
  28. #include "StandardMenus.h"
  29. #include "SplashWindow.h"
  30. #include "FuturesDemo.h"
  31.  
  32. #include <Desk.h>
  33. #include <Resources.h>
  34. #include <Errors.h>
  35.  
  36. #include "ToolWindow.h"
  37. #include "PictureWindow.h"
  38. #include "TextWindow.h"
  39. #include "PreferencesDialogWindow.h"
  40. #include "MailableDocWindow.h"
  41.  
  42. AppPreferences    gPreferences;
  43.  
  44. //    Function Prototypes:
  45.  
  46. void    AboutBox(void);
  47. void    OpenExistingDocument(void);
  48. OSErr    CreateNewTextWindow(void);
  49. OSErr    CreateNewPictureWindow(void);
  50.  
  51.  
  52. #define    mDebug                            256
  53. #define        iNewMailableWindow            1
  54.  
  55. #define    kAboutBoxFor68K                    256
  56. #define    kAboutBoxForPowerPC                257
  57. #define        iCreditsButton                2
  58.  
  59.  
  60. ////////////////////////////////////////////////////////////////////
  61. //
  62. //    SetupApplication
  63. //
  64. //    Modify this function to provide any application-specific
  65. //    initialization you may require.
  66. //
  67. //    This is a good place to call EnterMovies, allocate
  68. //    sound channels, setup network things, etc.
  69.  
  70. OSErr
  71. SetupApplication(void)
  72.     {
  73. #if    0
  74.     gListPtr = new TLinkedList;
  75. #endif
  76.  
  77.     TToolWindow    * someTools = new TToolWindow(1025);
  78.  
  79. #if    qAOCEAware
  80.     gPreferences.fMailPreferences.fCreateMailerForNewDocuments = true;
  81.  
  82.     InsertMenu(GetMenu(mDebug),0);                //    Add Debug Menu
  83.     gMenuBar->RegisterCommand(cNewMailableWindow,mDebug,1);
  84.     if (gHasAOCE)
  85.         EnableCommand(cNewMailableWindow,true);
  86. #endif
  87.     TTextWindow::SetUpStaticMenu();
  88.     TPictureWindow::SetUpStaticMenu();
  89.     
  90.     InitCursor();
  91.     InitFuturesDemo();
  92.     return noErr;
  93.     }
  94.  
  95.  
  96. ////////////////////////////////////////////////////////////////////
  97. //
  98. //    CreateNewPictureWindow
  99. //
  100. //    Create a new Picture window
  101.  
  102. OSErr
  103. CreateNewPictureWindow(void)
  104.     {
  105.     TPictureWindow    *aNewWindow = new TPictureWindow();
  106.     
  107.     if (aNewWindow)
  108.         return noErr;
  109.     else
  110.         return memFullErr;
  111.     }
  112.  
  113.  
  114. ////////////////////////////////////////////////////////////////////
  115. //
  116. //    CreateNewTextWindow
  117. //
  118. //    Create a new Text window
  119.  
  120. OSErr
  121. CreateNewTextWindow(void)
  122.     {
  123.     TTextWindow    *aNewWindow = new TTextWindow();
  124.     
  125.     if (aNewWindow)
  126.         return noErr;
  127.     else
  128.         return memFullErr;
  129.     }
  130.  
  131.  
  132. ////////////////////////////////////////////////////////////////////
  133. //
  134. //    TearDownApplication
  135. //
  136. //    Modify this function to tear down anything that you allocated
  137. //    from within SetupApplication.
  138.  
  139. void
  140. TearDownApplication(void)
  141.     {
  142.         CleanupFuturesDemo();
  143.     }
  144.  
  145.  
  146. ////////////////////////////////////////////////////////////////////
  147. //
  148. //    HandleMenuCommand
  149. //
  150. //    Modify this function to handle any registered menu commands
  151. //    that aren’t specific to a particular window.
  152.  
  153. void
  154. HandleMenuCommand(MenuCommandID theCommand)
  155.     {
  156.     switch (theCommand)
  157.         {
  158.         case    cAbout:
  159.             AboutBox();
  160.             break;
  161.             
  162.         case    cNewTextWindow:
  163.             CreateNewTextWindow();
  164.             break;
  165.             
  166.         case    cNewPictureWindow:
  167.             CreateNewPictureWindow();
  168.             break;
  169.             
  170.         case    cCentered:
  171.             SysBeep( 20 );
  172.             break;
  173.             
  174.         case    cUpperLeft:
  175.             SysBeep( 20 );
  176.             break;
  177.         
  178.         case    cOpen:
  179.             OpenExistingDocument();
  180.             break;
  181.             
  182.         case    cPreferences:
  183.             TPreferencesDialogWindow * prefsDialog = new TPreferencesDialogWindow;
  184.             break;
  185.                     
  186. #if    qAOCEAware
  187.         case    cNewMailableWindow:
  188.             TMailableDocWindow *aWackyThing = new TMailableDocWindow;
  189.             break;
  190. #endif
  191.     
  192.         case    cPing:
  193.             SendSimpleAEvt(kSillyEventClass, kPing1Event);
  194.             break;
  195.  
  196.         case    cPing2:
  197.             SendSimpleAEvt(kSillyEventClass, kPing2Event);
  198.             break;
  199.  
  200.         default:
  201.             break;
  202.         }
  203.     }
  204.  
  205.  
  206. ////////////////////////////////////////////////////////////////////
  207. //
  208. //    HandleMenuSelection
  209. //
  210. //    Modify this function to handle any menu selections that aren’t
  211. //    specific to a particular window. Normally, you shouldn’t need to
  212. //    do anything, unless you hate using MenuCommands.
  213.  
  214. void
  215. HandleMenuSelection(MenuID /* theMenu */, MenuItemID /* theItem */)
  216.     {
  217.     }
  218.  
  219.  
  220. ////////////////////////////////////////////////////////////////////
  221. //
  222. //    ReadLocalClipboardFromScrap & WriteLocalClipboardToScrap
  223. //
  224. //    These functions will be called whenever the user switches into
  225. //    or out of your application.
  226. //
  227. //    If you keep copy of the clipboard in your own data structures,
  228. //    these functions will allow you to keep it in synch so that the
  229. //    user can cut and paste information between your program and
  230. //    other applications.
  231. //
  232. //    We don’t actually use the clipboard in SprocketSample, so these
  233. //    functions are empty for now.
  234.  
  235. void
  236. ReadLocalClipboardFromScrap(void)
  237.     {
  238.     }
  239.  
  240. void
  241. WriteLocalClipboardToScrap(void)
  242.     {
  243.     }
  244.  
  245.  
  246. ////////////////////////////////////////////////////////////////////
  247. //
  248. //    CreateNewDocument, OpenDocument, PrintDocument, and
  249. //    QuitApplication.
  250. //
  251. //    These functions will be called whenever one of the required
  252. //    AppleEvents is sent to your application— either when your
  253. //    program is launched, or when the user opens a document from
  254. //    the Finder.
  255.  
  256. OSErr
  257. CreateNewDocument(void)
  258.     {
  259.     return CreateNewTextWindow();
  260.     }
  261.  
  262.  
  263. OSErr
  264. OpenDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
  265.     {
  266.     //    Normally, you would open the file (or letter) and use the
  267.     //    information to create windows, etc.
  268.     
  269.     //    For now, we just create a new document.
  270.  
  271.     return CreateNewDocument();
  272.     }
  273.  
  274.  
  275. OSErr
  276. PrintDocument(LetterDescriptor * /* theDocument */, void * /*unused*/)
  277.     {
  278.     //    We don’t do printing yet, but you could.
  279.     return errAEEventNotHandled;
  280.     }
  281.  
  282.  
  283. Boolean QuitApplication(void)
  284. {
  285.     //    Just go ahead and say we’re done quitting…
  286.     
  287.     //    Normally, you would offer to close any unsaved documents,
  288.     //    allowing the user to cancel along the way.
  289.  
  290. #if    0
  291.     unsigned long    numLinks, counter;
  292.     TDocWindow        *myDocPtr;
  293.     
  294.     numLinks = gListPtr->CountLinks();
  295.     for ( counter=1; counter<=numLinks; counter++ )
  296.     {
  297.         myDocPtr = (TDocWindow *)gListPtr->GetNthLinkObject( 1 );
  298. //    If the user cancels the close, return false to
  299. //    cancel the quit...
  300.         if ( ! myDocPtr->Close() )
  301.             return false;
  302.         else
  303.             delete myDocPtr;
  304.     }
  305. #endif
  306.     
  307.     return true;
  308. }
  309.  
  310.  
  311.  
  312. ////////////////////////////////////////////////////////////////////
  313. //
  314. //    AboutBox
  315. //
  316. //    Put up our about box, including the version number. Depending
  317. //    on what version we are running, pick the correct DLOG resource.
  318. //
  319.  
  320. void
  321. AboutBox(void)
  322.     {
  323.     Handle            versionHandle;
  324.     StringPtr        nullStr = (StringPtr) "\p";
  325.     StringPtr        shortVersionString = nullStr;
  326.     short            itemHit;
  327.     
  328.     versionHandle = GetResource('vers',1);
  329.     if (versionHandle)
  330.         shortVersionString = (StringPtr) ((char *) *versionHandle + 6);
  331.     ParamText(shortVersionString,nullStr,nullStr,nullStr);
  332.     ReleaseResource(versionHandle);
  333.  
  334. #if GENERATING68K
  335.     itemHit = StandardAlert(kAboutBoxFor68K);
  336. #else
  337.     itemHit = StandardAlert(kAboutBoxForPowerPC);
  338. #endif
  339.  
  340.     if (itemHit == iCreditsButton)
  341.         StandardAlert(kCreditsBox);
  342.     }
  343.  
  344.  
  345.  
  346. ////////////////////////////////////////////////////////////////////
  347. //
  348. //    OpenExistingDocument
  349. //
  350. //    Use StandardFile to ask the user for a file to open. We use
  351. //    CustomGetFile so that we can properly handle update events
  352. //    in other windows while the dialog is active.
  353.  
  354. void
  355. OpenExistingDocument(void)
  356.     {
  357.     StandardFileReply    reply;
  358.     SFTypeList            ourTypes;
  359.     
  360.     Point    where = { -1, -1 };
  361.     
  362.     HiliteWindowsForModalDialog(false);
  363.     CustomGetFile((FileFilterYDUPP) nil, -1, ourTypes, &reply, 0, where,
  364.                   (DlgHookYDUPP) nil,StandardDialogFilterYDUPP, nil,nil,nil);
  365.     HiliteWindowsForModalDialog(true);
  366.     }
  367.